package com.xb.loan.cashier.alipay.web.bean;

import com.xb.loan.cashier.alipay.util.UtilDate;

import java.util.*;

public class EnCashValueBean {
    private static List<String> collect_rows1 = new ArrayList<String>();

    private static List<String> collect_rows2 = new ArrayList<String>();

    private static List<String> collect_rows3 = new ArrayList<String>();

    private static List<String> detail_rows1 = new ArrayList<String>();
    
    private static List<String> refund_rows1 = new ArrayList<String>();
    private static List<String> refund_rows2 = new ArrayList<String>();

    static {

        collect_rows1.addAll(Arrays.asList("付款日期", "批次数", "已处理批次个数", "处理中批次个数"));
        collect_rows2.addAll(Arrays.asList("1", "1", "0"));
        collect_rows3.addAll(Arrays.asList("批次名称", " 处理状态", " 处理成功笔数", "处理失败笔数", "成功付款总金额", " 失败付款总金额 ", "处理日期", "支付宝帐号", "备注 "));
        detail_rows1.addAll(Arrays.asList("付款日期", "处理日期 ", "总笔数", "处理成功笔数", "处理失败笔数", "成功付款总金额", "失败付款总金额", "支付宝帐号(Email)"));
        
        // 退票信息
        refund_rows1.addAll(Arrays.asList("总金额", "总笔数", "支付宝账户"));
        refund_rows2.addAll(Arrays.asList("商户批次号", "商户流水号", "收款银行户名","收款银行账号","收款开户银行","收款开户银行","收款银行所在省份","收款银行所在市","收款支行","金额","对公对私标识","备注","提现流水号","退票日期","退票原因"));
    }
    /**
     * 退单数据  --  仅退单一条
     * @param list mock生成的推送给收银台的list
     * @return
     * 2016年1月28日 by zhangyi
     */
    public static List<List<String>> getRefundList(List<List<String>> list){
    	List<List<String>> listNew = new ArrayList<List<String>>();
    	listNew.add(refund_rows1);
    	listNew.add(new ArrayList<String>(){{
    		add("0"); add("1");add("");
    	}});
    	listNew.add(refund_rows2);
    	for (int i = 3; i < list.size(); i++) {
            if(list.get(i).get(9).equals("S")){
            	// 成功
            	final String orderId = list.get(i).get(0);
            	listNew.add(new ArrayList<String>(){{
		    		add(""); add(orderId);
		    	}});
            	break;
            }
            	
        }
    	return listNew;
    }
    public static List<List<String>> getAlipayEncashCollect(String batchId, List<List<String>> list, Map<String,Double> map) {
        Map<String, String> paramsMap = convertList2Map(list);
        List<List<String>> collectList = new ArrayList<List<String>>();
        collectList.add(collect_rows1);
        collect_rows2.add(0, paramsMap.get("date"));
        collectList.add(collect_rows2);
        collectList.add(collect_rows3);
        List<String> collect_row4 = new ArrayList<String>();
        collect_row4.add(batchId);
        collect_row4.add("已处理");
        collect_row4.add(String.valueOf(map.get("S")));
        collect_row4.add(String.valueOf(map.get("F")));
        collect_row4.add(String.valueOf(map.get("Smoney")));
        collect_row4.add(String.valueOf(map.get("Fmoney")));
        collect_row4.add(paramsMap.get("date"));
        collect_row4.add(paramsMap.get("accountId"));
        collect_row4.add("");
        collectList.add(collect_row4);
        return collectList;

    }

    public static List<List<String>> getAlipayEncashDetail(List<List<String>> list, Map<String,Double> map) {
        Map<String, String> paramsMap = convertList2Map(list);
        for (int i = 3; i < list.size(); i++) {
            list.get(i).remove(9);
            list.get(i).add(getStatusRandom(map,list.get(i).get(7)));
            list.get(i).add(UtilDate.getOrderNum());
            list.get(i).add("0");
            list.get(i).add("");
            list.get(i).add("");
        }
        list.remove(0);
        list.add(0,detail_rows1);
        List<String> detail_rows2 =new ArrayList<String>();
        detail_rows2.addAll( Arrays.asList(
                paramsMap.get("date"),
                paramsMap.get("date"),
                paramsMap.get("count"),
                String.valueOf(map.get("S")),
                String.valueOf(map.get("F")),
                String.valueOf(map.get("Smoney")),
                String.valueOf(map.get("Fmoney")),
                paramsMap.get("accountId")));
        list.remove(1);
        list.add(1, detail_rows2);
        list.get(2).remove(9);
        list.get(2).add("成功失败标志");
        list.get(2).add("提现流水号");
        list.get(2).add("是否退票 ");
        list.get(2).add("备注");
        list.get(2).add("原备注");
        return list;

    }

    private static Map<String, String> convertList2Map(List<List<String>> list) {
        Map<String, String> retMap = new HashMap<String, String>();
        retMap.put("date", list.get(1).get(0));
        retMap.put("money", list.get(1).get(1));
        retMap.put("count", list.get(1).get(2));
        retMap.put("accountId", list.get(1).get(3));
        return retMap;
    }
    
    private static String getStatusRandom(Map<String,Double> map, String money){
    	if(map == null){
    		map = new HashMap<String,Double>();
    		map.put("S", 0d);
    		map.put("Smoney", 0d);
    		map.put("Fmoney", 0d);
    		map.put("F", 0d);
    	}
    	if(map.get("S") == null){
    		map.put("S", 0d);
    		map.put("Smoney", 0d);
    	}
    	if(map.get("F") == null){
    		map.put("Fmoney", 0d);
    		map.put("F", 0d);
    	}
    	Double random1 = Math.random();
    	long longNum = Math.round(random1*100);
    	if(longNum > 30){
    		map.put("S", map.get("S")+ 1);
    		map.put("Smoney", map.get("Smoney") + Double.parseDouble(money));
    		return "S";
    	}
    	map.put("F", map.get("F")+ 1);
    	map.put("Fmoney", map.get("Fmoney") + Double.parseDouble(money));
    	return "F";
    }
    public static void main(String[] args) {
    	//getStatusRandom(new HashMap());
	}

}
